﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Puzzle.PuzzleService;

namespace Puzzle
{
    public partial class RankingPage : PhoneApplicationPage
    {
        public RankingPage()
        {
            InitializeComponent();
            Loaded += RankingPage_Loaded;
        }

        void RankingPage_Loaded(object sender, RoutedEventArgs e)
        {
            string top;
            if (NavigationContext.QueryString.TryGetValue("top", out top) && top.Equals(true.ToString()))
            {
                TitlePage.Text = "Top 5";
                var svc = new PuzzleRakingServiceClient();
                svc.GetTop5Completed += new EventHandler<GetTop5CompletedEventArgs>(svc_GetTop5Completed);
                svc.GetTop5Async();
            }
            else
            {
                TitlePage.Text = "All Records";
            }
            
        }

        void svc_GetTop5Completed(object sender, GetTop5CompletedEventArgs e)
        {
            lbPlayerRaking.ItemsSource = e.Result;
            lbPlayerRaking.UpdateLayout();
        }
    }
}